import sys


def output(lst):
    if lst == []:
        print("Nothing!")
        return
    print("----  商品列表  ----")
    for i in range(len(lst)):
        print('{}  {}  {}{}{}'.format(i, lst[i][0],
                                      '\033[35m', lst[i][1], '\033[0m'))


def shopping(products):
    cart = []
    while True:
        result = input(">>>")
        # print(result)
        if result == "q":
            break
        result = int(result)
        if result not in range(len(products)):
            print("Wrong Number!")
            continue
        cart.append(products[result])
        print(products[result][0], "is added to shopping cart.")
    output(cart)


def main():
    products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499],
                ["Coffee", 31], ["Book", 60], ["Nike", 699]]
    output(products)
    shopping(products)


if __name__ == '__main__':
    main()
<<<<<<< HEAD
=======
    # 有个小问题：请 显性的提示用户输入 q 退出，还有sys这个好像没有用。
>>>>>>> ecc71920a9832b7871ea27ab2da88baf6f86c8ae
